// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class MF_LOC_DEPT_MFN_M05 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("17 LDP",17)]
  	    [HL7Field(HL7Version.v23, 17, HL7Repeat.False, HL7Required.True,"LDP")]
	    public LDP LDP {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("20 LCH",20)]
  	    [HL7Field(HL7Version.v23, 20, HL7Repeat.True, HL7Required.False,"LCH")]
	    public LCH[] LCH {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("25 LCC",25)]
  	    [HL7Field(HL7Version.v23, 25, HL7Repeat.True, HL7Required.False,"LCC")]
	    public LCC[] LCC {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			LDP = PopSegmentParseAndCheckRequired<LDP>(availableData, options, "LDP");
			LCH = PopSegmentParseAndCheckRequiredArray<LCH>(availableData, options, "LCH");
			LCC = PopSegmentParseAndCheckRequiredArray<LCC>(availableData, options, "LCC");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isLDP = availableData.StartsWith("LDP", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("LDP", options.Version) || isLDP) {
				return isLDP;
			}
			bool isLCH = availableData.StartsWith("LCH", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("LCH", options.Version) || isLCH) {
				return isLCH;
			}
			bool isLCC = availableData.StartsWith("LCC", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("LCC", options.Version) || isLCC) {
				return isLCC;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "MF_LOC_DEPT";
			}
        }

        static MF_LOC_DEPT_MFN_M05() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(MF_LOC_DEPT_MFN_M05));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (LDP != null) {
			string segmentValue = LDP.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (LCH != null && LCH.Length > 0) {
			for (int i = 0; i < LCH.Length; i++) {
				string segmentValue = LCH[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (LCC != null && LCC.Length > 0) {
			for (int i = 0; i < LCC.Length; i++) {
				string segmentValue = LCC[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

